/**
* Created with JetBrains WebStorm.
* User: scb
* Date: 12/4/13
* Time: 11:44 AM
* To change this template use File | Settings | File Templates.
*/

describe("locateAtmBranchController", function() {
    var locateAtmBranchController = null;
    var channelType = "";
    beforeEach(function() {
        //need feature
        var t_alertCtrl = App.AlertController.create();
        var t_loadingCtrl = App.LoadingController.create();
        App.LocateAtmBranchController.reopen({
            init:function() {
                this.set('controllers.alert', t_alertCtrl);
                this.set('controllers.loading', t_loadingCtrl);
            }
        });
        locateAtmBranchController = App.LocateAtmBranchController.create();
    });

    it("prepareController", function() {
        locateAtmBranchController.set("controllers",Ember.Controller.extend({navbar:{}}));
//        spyOn(locateAtmBranchController, "prepareAtmBranchList");
//        spyOn(Ember, "isNone").andReturn(false);
        var areaObject = {
            placemarks:[{area:""},{area:""},{area:""},{area:""} ]
        }
//        App.Router.setParameter(areaObject);
//        App.RouteHistory.set("lastRoute", "publicLocate");
//        locateAtmBranchController.prepareController(channelType);

//        expect(locateAtmBranchController.prepareAtmBranchList).toHaveBeenCalled();
//        expect(Ember.isNone).toHaveBeenCalledWith(areaObject);
    });

    describe("prepareAtmBranchList", function() {
        it("prepareAtmBranchList; if selectedArea != null ATM", function() {
            var placemarksData = {
                placemarks: [
                    {channels:[{channelType:"ATM"}], latitude:"fakeData", longitude:"fakeData"},
                    {channels:[{channelType:"ATM"}], latitude:"fakeData1", longitude:"fakeData1"}
                ]
            };
            locateAtmBranchController.set('listData', []);
            locateAtmBranchController.set("selectedArea" , placemarksData)
            locateAtmBranchController.prepareAtmBranchList(placemarksData.placemarks,"atm");
            expect(locateAtmBranchController.listData.length).toBe(1);
        });

        it("prepareAtmBranchList; if selectedArea != null ATM5", function() {
            var placemarksData = {
                placemarks: [
                    {channels:[{channelType:"ATM5"}], latitude:"fakeData", longitude:"fakeData"},
                    {channels:[{channelType:"ATM5"}], latitude:"fakeData1", longitude:"fakeData1"}
                ]
            };
            locateAtmBranchController.set('listData', []);
            locateAtmBranchController.set("selectedArea" , placemarksData)
            locateAtmBranchController.prepareAtmBranchList(placemarksData.placemarks,"atm5");
            expect(locateAtmBranchController.listData.length).toBe(1);
        });

        it("prepareAtmBranchList; if selectedArea != null axs", function() {
            var placemarksData = {
                placemarks: [
                    {channels:[{channelType:"AXS"}], latitude:"fakeData", longitude:"fakeData"},
                    {channels:[{channelType:"AXS"}], latitude:"fakeData1", longitude:"fakeData1"}
                ]
            };
            locateAtmBranchController.set('listData', []);
            locateAtmBranchController.set("selectedArea" , placemarksData)
            locateAtmBranchController.prepareAtmBranchList(placemarksData.placemarks,"axs");
            expect(locateAtmBranchController.listData.length).toBe(1);
        });

        it("prepareAtmBranchList; if selectedArea != null Branch", function() {
            var placemarksData = {
                placemarks: [
                    {channels:[{channelType:"Branch"}], latitude:"fakeData", longitude:"fakeData"},
                    {channels:[{channelType:"Branch"}], latitude:"fakeData1", longitude:"fakeData1"}
                ]
            };
            locateAtmBranchController.set('listData', []);
            locateAtmBranchController.set("selectedArea" , placemarksData)
            locateAtmBranchController.prepareAtmBranchList(placemarksData.placemarks,"branch");
            expect(locateAtmBranchController.listData.length).toBe(1);
        });

        it("prepareAtmBranchList; if selectedArea === null ATM", function() {
            var placemarksData = {
                placemarks:{
                        atm:[
                            {channels:[{channelType:"ATM"}], latitude:"fakeData", longitude:"fakeData"},
                            {channels:[{channelType:"ATM"}], latitude:"fakeData1", longitude:"fakeData1"}
                        ]
                }
            };
            locateAtmBranchController.set('listData', []);
            locateAtmBranchController.set("selectedArea" , null);
            locateAtmBranchController.prepareAtmBranchList(placemarksData.placemarks,"atm");
            expect(locateAtmBranchController.listData.length).toBe(1);
        });

        it("prepareAtmBranchList; if selectedArea === null ATM5", function() {
            var placemarksData = {
                placemarks:{
                    atm5:[
                        {channels:[{channelType:"ATM5"}], latitude:"fakeData", longitude:"fakeData"},
                        {channels:[{channelType:"ATM5"}], latitude:"fakeData1", longitude:"fakeData1"}
                    ]
                }
            };
            locateAtmBranchController.set('listData', []);
            locateAtmBranchController.set("selectedArea" , null);
            locateAtmBranchController.prepareAtmBranchList(placemarksData.placemarks,"atm5");
            expect(locateAtmBranchController.listData.length).toBe(1);
        });

        it("prepareAtmBranchList; if selectedArea === null Branch", function() {
            var placemarksData = {
                placemarks:{
                    branch:[
                        {channels:[{channelType:"Branch"}], latitude:"fakeData", longitude:"fakeData"},
                        {channels:[{channelType:"Branch"}], latitude:"fakeData1", longitude:"fakeData1"}
                    ]
                }
            };
            locateAtmBranchController.set('listData', []);
            locateAtmBranchController.set("selectedArea" , null);
            locateAtmBranchController.prepareAtmBranchList(placemarksData.placemarks,"branch");
            expect(locateAtmBranchController.listData.length).toBe(1);
        });

        it("prepareAtmBranchList; if selectedArea === null axs", function() {
            var placemarksData = {
                placemarks:{
                    axs:[
                        {channels:[{channelType:"AXS"}], latitude:"fakeData", longitude:"fakeData"},
                        {channels:[{channelType:"AXS"}], latitude:"fakeData1", longitude:"fakeData1"}
                    ]
                }
            };
            locateAtmBranchController.set('listData', []);
            locateAtmBranchController.set("selectedArea" , null);
            locateAtmBranchController.prepareAtmBranchList(placemarksData.placemarks,"axs");
            expect(locateAtmBranchController.listData.length).toBe(1);
        });

    });

    it("selectItem method", function() {
        var obj = {
            channel:{},
            position: null
        };
        spyOn(App.RouteHistory, 'currentRoute').andReturn("publicLocate");
        spyOn(locateAtmBranchController, "transitionTo");
        locateAtmBranchController.selectItem(obj.channel);
        expect(locateAtmBranchController.transitionTo).toHaveBeenCalledWith('publicLocate.map', obj);
    });
});